package thread;

import io.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class StuCreate {
    public static void main(String[] args) throws  Exception {
        Class c=Class.forName("io.Student");
        //Student stu= (Student) c.newInstance();
        //System.out.println(stu);
        System.out.println("---2个参数的构造方法-------");
        Constructor<Student> cc=c.getDeclaredConstructor(String.class,String.class);
        cc.setAccessible(true);//突破访问权限的限制
        Student stu=   cc.newInstance("老刘","13848850");
        System.out.println(stu);
        System.out.println(">>>>>>>>>>>>>>>>>>>>.");
        Field fage=c.getDeclaredField("age");
        fage.setAccessible(true);
        fage.setInt(stu,34);//!!!!!!!!!!!!!!!!!!
        System.out.println(stu);
        System.out.println(">>>>>>>>>>>>>>>>-调用方法---------------------");
        Method mphone=c.getDeclaredMethod("setTelephone",String.class);
        Object rtn=mphone.invoke(stu,"13189025609");//调用方法
        System.out.println("rtn:"+rtn);
        System.out.println(stu);
    }
}
